package top.hekun.study.core.visitor.method.complex;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.commons.Method;

import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;

/**
 * 清除输出语句
 *
 * @Author: 贺坤
 * @Date: 2023/5/12 21:25
 */
public class MyClassVisitorComplexCode4 extends ClassVisitor {

    private String thisClassName = this.getClass().getSimpleName();

    public MyClassVisitorComplexCode4(int apiVersion, ClassVisitor classVisitor) {
        super(apiVersion, classVisitor);

    }

    @Override
    public void visitEnd() {
        System.out.println(thisClassName + " visitEnd");
        Method method = Method.getMethod("int testLambda (int,int)");
        // 添加方法
        // 根据方法调用顺序可知, visitMethod在visitEnd() 前调用
        MethodVisitor methodVisitor = super.visitMethod(ACC_PUBLIC, method.getName(),method.getDescriptor(), null, null);
        if (methodVisitor != null) {
            new MyMethodVisitor4(methodVisitor, method).code();
        }

        super.visitEnd();
    }
}
